package com.tal.jzb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiefengsong
 * @date 2019-01-24 15:16
 */
@RestController
@RequestMapping(value = "/redis")
public class RedisController {

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping(value = "setValue")
    public void setValue(@RequestParam String key, @RequestParam String value) {
        redisTemplate.opsForValue().set(key, value);
    }

    @GetMapping(value = "getValue")
    public Object getValue(@RequestParam String key) {
        Object result = redisTemplate.opsForValue().get(key);
        return result;
    }

    @GetMapping(value = "deleteKey")
    public Object deleteKey(@RequestParam String key) {
        return redisTemplate.delete(key);
    }
}
